//
//  LPZWYContentView.m
//  ZhongWangYuan
//
//  Created by liuyingping on 2018/6/2.
//  Copyright © 2018年 ZJ. All rights reserved.
//

#import "LPZWYContentView.h"

@implementation LPZWYContentView

- (instancetype)initWithFrame:(CGRect)frame  imageName:(NSString *)imageName  title:(NSString *)title content:(NSString *)content number:(NSString *)nmumber
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        UIImageView *imageView = [UIImageView new];
        imageView.contentMode = UIViewContentModeCenter;
        imageView.image = [UIImage imageNamed:imageName];

        [self addSubview:imageView];
        imageView.sd_layout
        .centerYEqualToView(self)
        .leftSpaceToView(self, 25 * [UIScreen zj_screenWScale])
        .heightIs(30 * [UIScreen zj_screenHScale])
        .widthIs(30 * [UIScreen zj_screenHScale]);
//        titleText  numberText
        UILabel *titleText = [[UILabel alloc] init];
        titleText.text = title;
        titleText.font = LYPFONT(18);
        titleText.textColor = [UIColor textGrayColor];
        [self addSubview:titleText];
        
        UILabel *numberText = [[UILabel alloc] init];
        numberText.font = LYPFONT(13);
        numberText.textColor = [UIColor zj_colorWithHexString:@"c6c6c6"];
        numberText.hidden = YES;
        [self addSubview:numberText];
        
        if ([content isEqualToString:@"noContent"]) {
            titleText.sd_layout
            .topSpaceToView(self, 10 * [UIScreen zj_screenHScale])
            .leftSpaceToView(imageView, 10 * [UIScreen zj_screenWScale])
            .heightIs(60 * [UIScreen zj_screenHScale])
            .widthIs([UIScreen zj_screenWith] / 2 - 70 * [UIScreen zj_screenWScale]);
        }
        else{
            titleText.sd_layout
            .topSpaceToView(self, 20 * [UIScreen zj_screenHScale])
            .leftSpaceToView(imageView, 10 * [UIScreen zj_screenWScale])
            .heightIs(20 * [UIScreen zj_screenHScale])
            .widthIs([UIScreen zj_screenWith] / 2 - 70 * [UIScreen zj_screenWScale]);
            
            numberText.hidden = NO;
            numberText.sd_layout
            .topSpaceToView(titleText, 10 * [UIScreen zj_screenHScale])
            .leftEqualToView(titleText)
            .heightIs(10 * [UIScreen zj_screenHScale])
            .widthIs([UIScreen zj_screenWith] / 2 - 70 * [UIScreen zj_screenWScale]);
            NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:content];
            NSRange range = [content rangeOfString:nmumber];
            [attributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor themeColor] range:NSMakeRange(range.location, nmumber.length)];
            numberText.attributedText = attributeStr;
        }
        
    }
    return self;
}

@end
